package map;

import java.io.Serializable;

/**
 * Represents a terrain tile in a MapData object
 * with a rotation and a type.
 * Its type corresponds to the ID of an entry in a MapLibrary.
 * Its rotation is an integer in quarter-turns clockwise
 * for it default position.
 * 
 * @author Alex Babis
 */
public class MapDataTerrainInstance implements Serializable
{
    private static final long serialVersionUID = 1L;
    private int type;		// Corresponds to an ID in the library
	private int rotation; 	// In quarter-turns clockwise
	
	/**
	 * Creates a new terrain tile
	 * @param type		The ID for the corresponding MapLibrary entry
	 * @param rotation	Direction of this tile in quarter-turns clockwise
	 * from the default position.
	 */
	public MapDataTerrainInstance(int type, int rotation)
	{
		this.type = type;
		this.rotation = rotation;
	}
	
	/** Gets a number corresponding to the ID in a MapLibrary
	 *  for this instance
	 * @return The terrain type for this entry */
	public int getType(){return type;}
	
	/** Gets the unique ID for this terrain entry
	 * @return The unique ID for this terrain entry */
	public int getRotation(){return rotation;}

	/** Rotates this tile 90 degrees clockwise */
	public void rotateCW(){rotation = (rotation + 1) % 4;}

	/** Rotates this tile 90 degrees counter-clockwise */
	public void rotateCCW(){rotation = (rotation + 3) % 4;}

	/** Sets the rotation of this tile in quarter-turns
	 * clockwise. 0 is the default position */
	public void setRotation(int rotation){this.rotation = rotation;}
}